use "/Users/jg74853/Desktop/Wave 2 Final/Wave 2 Final/Wave 2.dta"

***Define Variables***

generate PID3 =.
replace PID3 = 1 if PARTYID < 4
replace PID3 = 2 if PARTYID == 4
replace PID3 = 3 if PARTYID > 4 & PARTYID < 8 



gen DEM = 0
replace DEM = 1 if PID3 == 1
gen REP = 0
replace REP = 1 if PID3 == 3

label define PID3 1 "Dem" 2 "Ind" 3 "Rep"
label values PID3 PID3
label values PIDNI PID3

generate LIBCONV3 =.
replace LIBCONV3 = 0 if LIBCONV > 7 & LIBCONV < 98
replace LIBCONV3 = 1 if LIBCONV < 4
replace LIBCONV3 = 2 if LIBCONV == 4
replace LIBCONV3 = 3 if LIBCONV > 4 & LIBCONV < 8

label define LIBCONV3 0 "None" 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values LIBCONV3 LIBCONV3 

generate Q17C = Q17A
replace Q17C = Q17B if Q17A ==.

gen P1C = 0
replace P1C = 1 if P_ASSIGN1 == 1
gen P1T2 = 0
replace P1T2 = 1 if P_ASSIGN1 == 2
gen P1T3 = 0
replace P1T3 = 1 if P_ASSIGN1 == 3
gen P1T4 = 0
replace P1T4 = 1 if P_ASSIGN1 == 4
gen P1T5 = 0
replace P1T5 = 1 if P_ASSIGN1 == 5
gen P1T6 = 0
replace P1T6 = 1 if P_ASSIGN1 == 6
gen P1T7 = 0
replace P1T7 = 1 if P_ASSIGN1 == 7
gen P1T8 = 0
replace P1T8 = 1 if P_ASSIGN1 == 8

gen P1T5A = 0 if P_ASSIGN1 == 1
replace P1T5A = 1 if P_ASSIGN1 == 5

gen d5 =.
replace d5 = 0 if P_ASSIGN1 == 0
replace d5 = 1 if P_ASSIGN1 == 5

label define P_ASSIGN1 1 "Control" 2 "COVID Failure" 3 "COVID Success" 4 "NG Traditional" 5 "NG Controversial" 6 "GOP Military" 7 "Dem Military" 8 "Partisan Military"
label values P_ASSIGN1 P_ASSIGN1

generate P_ASSIGN1A = P_ASSIGN1
replace P_ASSIGN1A = . if P_ASSIGN1 > 1 & P_ASSIGN1 < 6

label define P_ASSIGN1A 1 "Control" 6 "GOP Military" 7 "Dem Military" 8 "Partisan Military"
label values P_ASSIGN1A P_ASSIGN1A

generate Post911 =.
replace Post911 = 0 if VETERAN == 1 & VETERAN4 == 1
replace Post911 = 1 if VETERAN == 1 & VETERAN4 > 1 & VETERAN4 == 2
replace Post911 = 0 if VETERAN == 1 & VETERAN4 > 1 & VETERAN4 == 3

label define Post911 0 "Served Before 9/11" 1 "Served After 9/11"
label values Post911 Post911

generate MILVET =.
replace MILVET = 0 if VETERAN > 1 & VETERAN < 77
replace MILVET = 1 if VETERAN == 1 & Post911 == 0
replace MILVET = 2 if VETERAN == 1 & Post911 == 1

label define MILVET 0 "Civilian" 1 "Veteran" 2 "Post911 Veteran"
label values MILVET MILVET

generate Q11T =.
replace Q11T = 0 if Q11 > 2
replace Q11T = 1 if Q11 < 3

replace Q11 =. if Q11 > 4
replace Q11T =. if Q11 > 4

generate Q16T =.
replace Q16T = 0 if Q16 > 2
replace Q16T = 1 if Q16 < 3

label define Confidence 0 "Not Confident" 1 "Confident"
label values Q11T Confidence

generate Q20DD2 = .
replace Q20DD2 = 1 if Q20DD < 3
replace Q20DD2 = 0 if Q20DD > 2 & Q20DD < 77

label define CRITICIZE 1 "Criticize Trump" 2 "Criticize Obama" 3 "Criticize POTUS"
label values P_Q20 CRITICIZE 


generate Q13B2 =.
replace Q13B2 = 0 if Q13B > 2 & Q13B < 6
replace Q13B2 = 1 if Q13B < 3

generate Q13E2 =.
replace Q13E2 = 0 if Q13E > 2 & Q13E < 6
replace Q13E2 = 1 if Q13E < 3

generate Q13F2 =.
replace Q13F2 = 0 if Q13F > 2 & Q13F < 6
replace Q13F2 = 1 if Q13F < 3

generate Q13D2 =.
replace Q13D2 = 0 if Q13D > 2 & Q13D < 6
replace Q13D2 = 1 if Q13D < 3

generate Q13H2 =.
replace Q13H2 = 0 if Q13H > 2 & Q13H < 6
replace Q13H2 = 1 if Q13H < 3

gen D2 = 0
gen D3 = 0
gen D4 = 0
gen D5 = 0
gen R2 = 0
gen R3 = 0
gen R4 = 0
gen R5 = 0

replace D2 = 1 if DEM == 1 & P_ASSIGN1 == 2
replace D3 = 1 if DEM == 1 & P_ASSIGN1 == 3
replace D4 = 1 if DEM == 1 & P_ASSIGN1 == 4
replace D5 = 1 if DEM == 1 & P_ASSIGN1 == 5
replace R2 = 1 if REP == 1 & P_ASSIGN1 == 2
replace R3 = 1 if REP == 1 & P_ASSIGN1 == 3
replace R4 = 1 if REP == 1 & P_ASSIGN1 == 4
replace R5 = 1 if REP == 1 & P_ASSIGN1 == 5



*********Table 5.1************
tab Q13B2 PID3 if P_ASSIGN1 == 1 [aweight=weight2], column
tab Q13H2 PID3 if P_ASSIGN1 == 1 [aweight=weight2], column

*********Figure 5.1************
mean Q11T if P_ASSIGN1 < 6 [pweight=weight2], over(P_ASSIGN1)
mean Q11T if P_ASSIGN1 < 6 [pweight=weight2], over(PID3 P_ASSIGN1)

logit Q11T P1T2 P1T3 P1T4 P1T5 if P_ASSIGN1 < 6 [pweight=weight2]

logit Q11T DEM REP P1T2 D2 R2 P1T3 D3 R3 P1T4 D4 R4 P1T5 D5 R5 if P_ASSIGN1 < 6 [pweight=weight2]

graph bar (mean) Q11T [pweight = weight2] if P_ASSIGN1 < 6, over(P_ASSIGN1, label(labsize(small))) blabel(bar, format(%3.2f))
graph bar (mean) Q11T [pweight = weight2] if P_ASSIGN1 < 6, over(P_ASSIGN1, label(angle(vertical) labsize(small))) over(PID3) blabel(bar, format(%3.2f))

********************
gen d5=.
replace d5 = 0 if P_ASSIGN1 == 1
replace d5 = 1 if P_ASSIGN1 == 5

mean Q16T [pweight=weight2], over(P_BRANCH d5) cformat(%9.2f)


*********Table 5.2************
tab Q13D2 PID3 if P_ASSIGN1 == 1 [aweight=weight2], column
tab Q13E2 PID3 if P_ASSIGN1 == 1 [aweight=weight2], column
tab Q13F2 PID3 if P_ASSIGN1 == 1 [aweight=weight2], column





**********
tab Q11T P_ASSIGN1 if P_ASSIGN1 < 6, column

mean Q11T if P_ASSIGN1 < 6 [pweight=weight2], over(P_ASSIGN1)

